<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;

/**
 * 微信绑定用户 控制器
 * @package app\user\admin
 */
class Userwechat extends Admin
{
	
    /**
     * 微信绑定用户
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
	public function wechat_list(){
		cookie('__forward__', $_SERVER['REQUEST_URI']);
		
		// 获取排序
        $order = $this->getOrder();
        // 获取筛选
        $map = $this->getMap();
		
		// 数据列表
        $map[] = ['uid', '>', 0];
        $data_list = model('UcMemberWechat', 'model\user') -> where($map) -> order($order) -> paginate();
		
		$rel_list = [];
		foreach($data_list as $key=> $value){
			$rel_list[$key] = $value;
			$rel_list[$key]['nick_name'] = $value['get_uc_member']['nick_name'];
		}

		// 使用ZBuilder快速创建数据表格
        return ZBuilder::make('table')
            ->setPageTitle('微信绑定用户管理') // 设置页面标题
            ->setTableName('uc_member_wechat') // 设置数据表名
			->setSearch(['uid' => '会员UID', 'unionid' => 'unionid']) // 设置搜索参数
            ->addColumns([
                ['__INDEX__', '序号'],
                ['uid', 'UID'],
                ['nick_name', '昵称'],
				['open_id', 'openid'],
				['unionid', 'unionid'],
                ['create_time', '创建时间', 'datetime'],
                ['right_button', '操作', 'btn']
            ])
            ->addFilter(['nick_name']) // 添加筛选
            ->addTimeFilter('create_time', '', ['开始时间', '结束时间'])
            ->addOrder('uid,create_time') // 添加排序
			->addRightButton('delete', ['title' => '解绑', 'icon' => 'fa fa-fw fa-unlink']) // 添加授权按钮
            ->setRowList($data_list) // 设置表格数据
            ->fetch(); // 渲染页面
	}
	
}
